package com.syq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.syq.mapper.DtsPermissionMapper;
import com.syq.pojo.DtsPermission;
import com.syq.service.DtsPermissionService;
import com.syq.vo.PermUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

/**
 * @ClassName: DtsPermissionServiceImpl
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/29 14:51
 */
@Transactional
@Service
public class DtsPermissionServiceImpl implements DtsPermissionService {
    @Autowired
    private DtsPermissionMapper dtsPermissionMapper;

    @Override
    public Set<String> findById(Integer roleId) {
        Set<String> permissionListById=dtsPermissionMapper.findById(roleId);
        if (permissionListById.contains("*")){
            return dtsPermissionMapper.findAll();
        }
        return permissionListById;
    }

    @Override
    public void updatePerm(PermUpdateVo permUpdateVo) {
        dtsPermissionMapper.delete(new QueryWrapper<DtsPermission>()
                .eq("role_id",permUpdateVo.getRoleId()));

        dtsPermissionMapper.insertAll(permUpdateVo);
    }
}
